// 网络请求

import MyRequest from './AxiosInterceptors'
import { weatherIncludesType, type LocationResponse } from '@/types/weather'
// import axios from 'axios'
// import { md5 } from 'js-md5'

const request = {
  // 和风天气API查找位置
  get_HF_Location: (location: string) => {
    return MyRequest.get(`/geo/v2/city/lookup?location=${location}&number=8&lang=zh`)
  },
  //腾讯地图API查找位置
  Get_Tx_Map_Location: (): Promise<LocationResponse> => {
    // const MapKey = import.meta.env.VITE_MAP_KEY
    // const sk = 'Sh0PgymXEFQ9nYp12DJWGinvENIlZDiz'
    // const str = `/ws/location/v1/ip?key=JAUBZ-OJPK3-35R33-RRPEJ-WET7Q-GBB3V${sk}`
    // const sig = md5(str)
    // console.log('sig', sig, '拼接后的url ', str)
    // return axios.get(`/ws/location/v1/ip?key=${MapKey}&sig=${sig}`)
    return new Promise((resolve) => {
      const data = {
        data: {
          status: 0,
          message: 'Success',
          request_id: '4e8a1432f44f4414aa546e460dbd8257',
          result: {
            ip: '116.253.144.134',
            location: {
              lat: 23.8066,
              lng: 108.88611,
            },
            ad_info: {
              nation: '中国',
              province: '广西壮族自治区',
              city: '来宾市',
              district: '合山市',
              adcode: 451381,
              nation_code: 156,
            },
          },
        },
      }
      resolve(data)
    })
  },
  // 实时天气
  Real_time_weather: (location: string) => {
    return MyRequest.get(`/v7/weather/now?location=${location}`)
  },
  /**
   * 获取空气质量
   * @param latitude 纬度
   * @param longitude 经度
   */
  Get_Air_Quality: (latitude: string | number, longitude: string | number) => {
    return MyRequest.get(`/airquality/v1/current/${latitude}/${longitude}`)
  },
  // 天气指数预报
  getweatherInclueds(
    days: number,
    type: weatherIncludesType = weatherIncludesType.ALL,
    location: string,
  ) {
    return MyRequest.get(`/v7/indices/${days}d?type=${type}&location=${location}`)
  },
  /**
   *
   * @param day 天数
   * @param location 位置
   */
  getWetherFuture(day: number = 7, location: string) {
    return MyRequest.get(`/v7/weather/${day}d?location=${location}`)
  },
  // 获取小时天气
  gethoursWeather(hours: number, location: string) {
    return MyRequest.get(`/v7/weather/${hours}h?location=${location}`)
  },
  // 获取预警信息
  getWarningInfo(localtion: string) {
    return MyRequest.get(`/v7/warning/now?location=${localtion}`)
  },
}
export default request
